convert teletype to Format class. (#836)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 29 Jan 2022 15:59:14 +0000 (08:59 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 15:59:14 +0000 (08:59 -0700)
* convert teletype to Format class.

* add default init.

CMakeLists.txt
GPSBabel.pro
teletype.cc
teletype.h [new file with mode: 0644]
vecs.h

index fe1e5bcf3e24fa7e8692cbaf52a99bb7ee949172..a8a4a19cd447ca123be337b10fa224507ef324ad 100644 (file)
@@ -256,6 +256,7 @@ set(HEADERS
   skytraq.h
   strptime.h
   subrip.h
+  teletype.h
   unicsv.h
   units.h
   vecs.h
index 01ac589664b921b273f9c532c4702863f52be244..035a8067bb5c1d74edf2b0501a30ad299f668e18 100644 (file)
@@ -243,6 +243,7 @@ HEADERS =  \
   skytraq.h \
   strptime.h \
   subrip.h \
+  teletype.h \
   unicsv.h \
   units.h \
   vecs.h \
index da1c6c5b02d1708baded9671f8e5857286275725..2841a2968b2c3eca8b027b7a48d8a277b30b7002 100644 (file)
 
  */
 
-#include "defs.h"
+#include "teletype.h"
+
+#include <cstdio>   // for SEEK_CUR
+#include "defs.h"   // for Waypoint, waypt_add
 
-#define MYNAME "teletype"
 
+#define MYNAME "teletype"
 
-static
-QVector<arglist_t> teletype_args = {
-};
 
 /*******************************************************************************
 * %%%        global callbacks called by gpsbabel main process              %%% *
 *******************************************************************************/
 
-static uint32_t tty_wpt_count;
-static gbfile* fin;
-
-static void
-teletype_rd_init(const QString& fname)
+void
+TeletypeFormat::rd_init(const QString& fname)
 {
   char header[64];
 
@@ -47,14 +44,14 @@ teletype_rd_init(const QString& fname)
   tty_wpt_count = gbfgetint32(fin);
 }
 
-static void
-teletype_rd_deinit()
+void
+TeletypeFormat::rd_deinit()
 {
   gbfclose(fin);
 }
 
-static void
-teletype_read()
+void
+TeletypeFormat::read()
 {
   for (uint32_t i = 0; i < tty_wpt_count; i++) {
     auto* wpt = new Waypoint;
@@ -79,30 +76,3 @@ teletype_read()
     waypt_add(wpt);
   }
 }
-
-/**************************************************************************/
-
-// capabilities below means: we can only read and write waypoints
-// please change this depending on your new module
-
-ff_vecs_t teletype_vecs = {
-  ff_type_file,
-  {
-    (ff_cap)(ff_cap_read)      /* waypoints */,
-    ff_cap_none                        /* tracks */,
-    ff_cap_none                        /* routes */
-  },
-  teletype_rd_init,
-  nullptr,
-  teletype_rd_deinit,
-  nullptr,
-  teletype_read,
-  nullptr,
-  nullptr,
-  &teletype_args,
-  CET_CHARSET_ASCII, 0                 /* ascii is the expected character set */
-  /* not fixed, can be changed through command line parameter */
-  , NULL_POS_OPS,
-  nullptr
-};
-/**************************************************************************/
diff --git a/teletype.h b/teletype.h
new file mode 100644 (file)
index 0000000..09c90c1
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+
+    teletype .way module
+
+    Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef TELETYPE_H_INCLUDED_
+#define TELETYPE_H_INCLUDED_
+
+#include <QString>   // for QString
+#include <QVector>   // for QVector
+
+#include <cstdint>   // for uint32_t
+
+#include "defs.h"    // for ff_cap, arglist_t, ff_cap_none, CET_CHARSET_ASCII, ff_cap_read, ff_type, ff_type_file
+#include "format.h"  // for Format
+#include "gbfile.h"  // for gbfile
+
+
+class TeletypeFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &teletype_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /*                  waypoints,      tracks,      routes */
+    return {(ff_cap)(ff_cap_read), ff_cap_none, ff_cap_none};
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_ASCII;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void rd_deinit() override;
+
+private:
+  /* Data Members */
+
+  uint32_t tty_wpt_count{};
+  gbfile* fin{};
+
+  QVector<arglist_t> teletype_args = {
+  };
+
+};
+#endif // TELETYPE_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index c5f0d7a2b88e4405625819be946d45fe1a6d627a..a8ba3260e512bcdcff11bd0df9a5a5190052e0f0 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -47,6 +47,7 @@
 #include "shape.h"
 #include "skytraq.h"
 #include "subrip.h"
+#include "teletype.h"
 #include "unicsv.h"
 #include "wintec_tes.h"
 #include "xcsv.h"
@@ -122,7 +123,6 @@ extern ff_vecs_t sbn_vecs;
 extern ff_vecs_t mmo_vecs;
 extern ff_vecs_t v900_vecs;
 extern ff_vecs_t enigma_vecs;
-extern ff_vecs_t teletype_vecs;
 extern ff_vecs_t format_garmin_xt_vecs;
 extern ff_vecs_t mapbar_track_vecs;
 extern ff_vecs_t f90g_track_vecs;
@@ -312,7 +312,7 @@ private:
   LegacyFormat v900_fmt {v900_vecs};
   LegacyFormat enigma_fmt {enigma_vecs};
   SkytraqFormat skytraq_fmt;
-  LegacyFormat teletype_fmt {teletype_vecs};
+  TeletypeFormat teletype_fmt;
   SkytraqfileFormat skytraq_ffmt;
   MinihomerFormat miniHomer_fmt;
   WintecTesFormat wintec_tes_fmt;